﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ServiceModel.Web;
using Intergr8.GoogleVisualization;
using Intergr8.GoogleVisualization.Interfaces;

namespace WCFDataService
{
    /// <summary>
    /// Manages the creation and population of the DataResponse object
    /// </summary>
    public class WCFDataResponseFactory
    {

        public static DataResponse CreateDataResponse(IResponseMessage message)
        {
            DataResponse dr = new DataResponse();

            // Defaults
            dr.version = message.MetaData.TQX.Version;
            dr.status = message.Status;
            dr.reqId = message.MetaData.TQX.ReqId.ToString();
            dr.sig = message.Sig.ToString() ;
            dr.errors = message.Errors.toJSON() == String.Empty?null:message.Errors.toJSON();
            dr.warnings = message.Warnings.toJSON() == String.Empty ? null : message.Warnings.toJSON(); 
            dr.table = message.Data.toJSON;          

            return dr;
        }

    }
}
